package meta

import (
	apiv1 "gomod.alauda.cn/mysql-mgr-operator/api/v1"
	"satellite/pkg/uix"
)

type ClearOption struct {
	IsForce bool
}

type Clear struct {
	*ClearOption
	*Base
}

func NewClear(opt *ClearOption) *Clear {
	return &Clear{
		ClearOption: opt,
	}
}

func (s *Clear) WithBase(base *Base) *Clear {
	s.Base = base
	return s
}

func (s *Clear) Run() error {
	if !s.IsForce && !uix.Confirm("Are you sure to clear meta?") {
		return nil
	}
	metaCr, err := s.getMeta()
	if err != nil {
		return err
	}
	metaCr.Status.Version = 1
	metaCr.Status.BackupInfos = make([]*apiv1.BackupInfo, 0)
	metaCr.Status.ValidTimeRanges = make([]*apiv1.TimeRange, 0)
	err = s.updateStatus(metaCr)
	if err != nil {
		return err
	}
	return nil
}
